var jsCode = [
  '"use strict";',
  "function Person(age) {",
  "	if (age) {",
  "		this.age = age;",
  "	}",
  "}",
  "Person.prototype.getAge = function () {",
  "	return this.age;",
  "};",
].join("\n");

var editor = monaco.editor.create(document.getElementById("container"), {
  value: jsCode,
  language: "javascript",
});

var myCondition1 = editor.createContextKey(
  /*key 名*/ "myCondition1",
  /*默认值*/ false
);
var myCondition2 = editor.createContextKey(
  /*key 名*/ "myCondition2",
  /*默认值*/ false
);

editor.addCommand(
  monaco.KeyCode.Tab,
  function () {
    // 在当前编辑器上下文中，此服务已可用
    alert("my command is executing!");
  },
  "myCondition1 && myCondition2"
);

myCondition1.set(true);

setTimeout(function () {
  alert("now enabling also myCondition2, try pressing Tab!");
  myCondition2.set(true);
  // 你可以调用 myCondition2.reset() 重置为默认值
}, 2000);
